package com.yxw.yx_hotel.controller;

import com.yxw.yx_hotel.dto.user.*;
import com.yxw.yx_hotel.service.UserService;
import com.yxw.yx_hotel.vo.UserAccountVO;
import com.yxw.yx_hotel.vo.UserCenterInfoVO;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author fangmaoxin
 * @version 1.0
 * @date 2024年1月24日
 * 登录账号管理相关
 */
@RestController
@Api(value = "登录账号管理", tags = "登录账号管理")
@Slf4j
@RequestMapping("/user/v1")
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 查询登录账号列表
     */
    @PostMapping("/getUserAccountList")
    @ApiOperation("查询登录账号列表")
    public BaseResult<PageVO<UserAccountVO>> listUserAccount(@RequestParam("userId") Long userId, @RequestBody @Validated UserAccountQueryDTO dto) {
        PageVO<UserAccountVO> tenantList = userService.getUserAccountList(userId, dto);
        return BaseResult.doSuccess(tenantList, "操作成功！");
    }

    /**
     * 添加登录账号-子账户
     */
    @PostMapping("/addUserAccount")
    @ApiOperation("添加登录账号-子账户")
    public BaseResult addUserAccount(@RequestBody @Validated UserAccountAddDTO dto) {
        userService.addUserAccount(dto);
        return BaseResult.doSuccess(null, "添加子账号成功");
    }

    /**
     * 修改账号信息-子账户
     */
    @PostMapping("/updateUserAccount")
    @ApiOperation("修改账号信息-子账户")
    public BaseResult updateUserAccount(@RequestBody @Validated UserAccountUpdateDTO dto) {
        userService.updateUserAccount(dto);
        return BaseResult.doSuccess(null, "修改子账号成功");
    }

    /**
     * 删除账号信息-子账户
     */
    @PostMapping("/deleteUserAccount")
    @ApiOperation("删除账号信息-子账户")
    public BaseResult deleteUserAccount(@RequestBody @Validated UserAccountDeleteDTO dto) {
        userService.deleteUserAccount(dto);
        return BaseResult.doSuccess(null, "删除子账号成功");
    }


    /**
     * 个人中心-查询账号信息
     */
    @PostMapping("/getUserCenterInfo")
    @ApiOperation("个人中心-查询账号信息")
    public BaseResult<UserCenterInfoVO> getUserCenterInfo(@RequestBody @Validated UserCenterInfoQueryDTO dto) {
        UserCenterInfoVO vo = userService.getUserCenterInfo(dto);
        return BaseResult.doSuccess(vo, "操作成功！");
    }

    /**
     * 个人中心-修改账号信息
     */
    @PostMapping("/updateUserCenterInfo")
    @ApiOperation("个人中心-修改账号信息")
    public BaseResult updateUserCenterInfo(@RequestBody @Validated UserCenterInfoUpdateDTO dto) {
        userService.updateUserCenterInfo(dto);
        return BaseResult.doSuccess(null, "操作成功！");
    }
}
